﻿<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" Inherits="System.Web.Mvc.ViewPage<PortalUser>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Head" runat="server">
<% this.Title = JSC.Portal.Web.App.Resources.Msg.UserManagement;  %>
<script type="text/javascript">
    $(function() {
        $("#gridroles").flexigrid({
            usepager: false, title: "<%= JSC.Portal.Web.App.Resources.Msg.Role %>", useRp: false, height: 100
        });
    });

    $(document).ready(function() {
        $("#formulier").validate(
        {
            rules:
            {
                username: {
                    required: true,
                    minlength: 3
                },
                password: {
                    required: true,
                    minlength: 5
                },
                confirm_password: {
                    required: true,
                    minlength: 5,
                    equalTo: '#password'
                },
                lastname: 'required',
                firstname: 'required',
                email: {
                    required: true,
                    email: true
                }
            },
            messages:
            {
                username: {
                    required: '*',
                    minlength: '<%= string.Format(JSC.Portal.Web.App.Resources.Msg.FieldXMinXLength, JSC.Portal.Web.App.Resources.Msg.Username, 3) %>'
                },
                password: {
                    required: '*',
                    minlength: '<%= string.Format(JSC.Portal.Web.App.Resources.Msg.FieldXMinXLength, JSC.Portal.Web.App.Resources.Msg.Password, 5) %>'
                },
                confirm_password: {
                    required: '*',
                    minlength: '<%= string.Format(JSC.Portal.Web.App.Resources.Msg.FieldXMinXLength, JSC.Portal.Web.App.Resources.Msg.Password, 5) %>',
                    equalTo: '<%= string.Format(JSC.Portal.Web.App.Resources.Msg.XEqualToAbove, JSC.Portal.Web.App.Resources.Msg.Password.ToLower()) %>'
                },
                lastname: '*',
                firstname: '*',
                email: '*'
            }
    });
    $("#username").focus(function() {
        var firstname = $("#firstname").val();
        var lastname = $("#lastname").val();
        if (firstname && lastname && !this.value) {
            this.value = firstname.toLowerCase() + "." + lastname.toLowerCase();
        }
    });
});
 
function Delete() {
    if (confirm('<%= JSC.Portal.Web.App.Resources.Msg.AreYouSureYouWantToDeleteThis %>')) {
        window.location = '<%= Url.Action("Delete", new { id = ViewData.Model.Id }) %>';
    }
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<form id="formulier" method="post" action="<%= Url.Action("SaveOrUpdate", new { id = ViewData.Model.Id }) %>">
    <fieldset class="contentfieldset">
        <legend><%= JSC.Portal.Web.App.Resources.Msg.General %></legend>
        <table border="0">
            <tr>
                <td class="tdCaption"><%= JSC.Portal.Web.App.Resources.Msg.LastName %></td>
                <td><%= Html.TextBox("lastname")%></td>
            </tr>
            <tr>
                <td class="tdCaption"><%= JSC.Portal.Web.App.Resources.Msg.FirstName %></td>
                <td><%= Html.TextBox("firstname")%></td>
            </tr>
            <tr>
                <td class="tdCaption"><%= JSC.Portal.Web.App.Resources.Msg.Username %></td>
                <td><%= Html.TextBox("username") %></td>
            </tr>
            <tr>
                <td class="tdCaption"><%= JSC.Portal.Web.App.Resources.Msg.Password %></td>
                <td><%= Html.Password("password") %></td>
            </tr>
            <tr>
                <td class="tdCaption"><%= JSC.Portal.Web.App.Resources.Msg.PasswordConfirm %></td>
                <td><%= Html.Password("confirm_password")%></td>
            </tr>
            <tr>
                <td class="tdCaption"><%= JSC.Portal.Web.App.Resources.Msg.IsActive %></td>
                <td><%= Html.CheckBox("isactive") %></td>
            </tr>
            <tr>
                <td class="tdCaption"><%= JSC.Portal.Web.App.Resources.Msg.EMail %></td>
                <td><%= Html.TextBox("email")%></td>
            </tr>
            <% if (ViewContext.CurrentUserIsInRole(JSC.Portal.Entities.Roles.Administrator) && !ViewData.Model.IsNew) { %>
            <tr>
                <td class="tdCaption"><%= JSC.Portal.Web.App.Resources.Msg.PortalSites %></td>
                <td><%= Html.DropDownList("portalsiteId", (SelectList)ViewData["PortalSites"], JSC.Portal.Web.App.Resources.Msg.PleaseMakeAChoice)%></td>
            </tr>
            <% } %>
        </table>    
    </fieldset>
    <table id="gridroles">
        <thead>
            <tr>
                <th width="200"><%= JSC.Portal.Web.App.Resources.Msg.Role %></th>
            </tr>
        </thead>
        <tbody>
            <%foreach (Role r in ((IDictionary<Role, bool>)ViewData["Roles"]).Keys){ %>
                <tr>
                    <td><label for="role"><%= Html.Encode(r.Name) %></label></td>
                    <% var ischecked = false; ((IDictionary<Role, bool>)ViewData["Roles"]).TryGetValue(r, out ischecked); %>
                    <td><%= Html.CheckBox("selectedRoles", r.Id.ToString(), ischecked)%></td>
                </tr>
            <%}%>
        </tbody>
    </table>
    <br />
    <div class="button-bar-right">
        <%= Html.LinkButtonRight(JSC.Portal.Web.App.Resources.Msg.Cancel, Url.Action("List"))%>
        <%= Html.SeperatorRight() %>
        <% if (ViewData.Model.CanDelete) { %>
        <%= Html.LinkButtonRight(JSC.Portal.Web.App.Resources.Msg.Delete, "javascript:Delete()")%>
        <% } %>
        <%= Html.SeperatorRight() %>
        <%= Html.SubmitButtonRight(JSC.Portal.Web.App.Resources.Msg.Save)%>
    </div>
</form>
</asp:Content>
